package net.wanho.controller;

import lombok.RequiredArgsConstructor;
import net.wanho.dto.OutStoreDTO;
import net.wanho.service.OutStoreService;
import net.wanho.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/outstore")
@RequiredArgsConstructor
public class OutStoreController {
    private final OutStoreService outStoreService;

    /**
     * 分页查询出库单
     */
    @GetMapping("/outstore-page-list")
    public AjaxResult outStorePageList(OutStoreDTO outStoreDTO,
                                       @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                       @RequestParam(required = false, defaultValue = "5") Integer pageSize) {
        return AjaxResult.success(outStoreService.getPageList(outStoreDTO, pageNum, pageSize));
    }

    /**
     * 添加出库单
     */
    @PostMapping("/outstore-add")
    public AjaxResult addOutStore(OutStoreDTO outStoreDTO) {
        outStoreService.addOutStore(outStoreDTO);
        return AjaxResult.success(null, "添加出库单成功！");
    }

    /**
     * 确认出库
     */
    @PutMapping("/outstore-confirm")
    public AjaxResult confirmOutStore(OutStoreDTO outStoreDTO) {
        outStoreService.updateOutStoreById(outStoreDTO);
        return AjaxResult.success(null, "出库成功！");
    }

    @GetMapping("/exportTable")
    public AjaxResult exportTable(OutStoreDTO outStoreDTO,
                                  @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                  @RequestParam(required = false, defaultValue = "5") Integer pageSize) {
        return AjaxResult.success(outStoreService.getPageList(outStoreDTO, pageNum, pageSize).getResultList());
    }
}
